from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-02 14:02:38.172730
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 02, Jan, 2023
Time: 14:02:45
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3535
Nobs: 889.000 HQIC: -51.6531
Log likelihood: 11779.3 FPE: 3.06800e-23
AIC: -51.8384 Det(Omega_mle): 2.77417e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296680 0.049163 6.035 0.000
L1.Burgenland 0.105895 0.033803 3.133 0.002
L1.Kärnten -0.106340 0.018153 -5.858 0.000
L1.Niederösterreich 0.213441 0.070882 3.011 0.003
L1.Oberösterreich 0.081519 0.067018 1.216 0.224
L1.Salzburg 0.250387 0.035901 6.974 0.000
L1.Steiermark 0.029671 0.047118 0.630 0.529
L1.Tirol 0.126520 0.038311 3.302 0.001
L1.Vorarlberg -0.060164 0.032914 -1.828 0.068
L1.Wien 0.066549 0.059754 1.114 0.265
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061650 0.100899 0.611 0.541
L1.Burgenland -0.009418 0.069375 -0.136 0.892
L1.Kärnten 0.049297 0.037256 1.323 0.186
L1.Niederösterreich -0.170306 0.145473 -1.171 0.242
L1.Oberösterreich 0.360367 0.137543 2.620 0.009
L1.Salzburg 0.285872 0.073681 3.880 0.000
L1.Steiermark 0.107423 0.096702 1.111 0.267
L1.Tirol 0.319319 0.078628 4.061 0.000
L1.Vorarlberg 0.025135 0.067551 0.372 0.710
L1.Wien -0.023518 0.122634 -0.192 0.848
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201285 0.025568 7.872 0.000
L1.Burgenland 0.090759 0.017580 5.163 0.000
L1.Kärnten -0.008785 0.009441 -0.931 0.352
L1.Niederösterreich 0.266831 0.036864 7.238 0.000
L1.Oberösterreich 0.110141 0.034854 3.160 0.002
L1.Salzburg 0.053575 0.018671 2.869 0.004
L1.Steiermark 0.015813 0.024505 0.645 0.519
L1.Tirol 0.101532 0.019925 5.096 0.000
L1.Vorarlberg 0.057555 0.017118 3.362 0.001
L1.Wien 0.112262 0.031076 3.612 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105721 0.026210 4.034 0.000
L1.Burgenland 0.048317 0.018021 2.681 0.007
L1.Kärnten -0.016289 0.009678 -1.683 0.092
L1.Niederösterreich 0.197483 0.037789 5.226 0.000
L1.Oberösterreich 0.276158 0.035729 7.729 0.000
L1.Salzburg 0.117640 0.019140 6.146 0.000
L1.Steiermark 0.100702 0.025120 4.009 0.000
L1.Tirol 0.125194 0.020425 6.129 0.000
L1.Vorarlberg 0.070611 0.017548 4.024 0.000
L1.Wien -0.026375 0.031857 -0.828 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132930 0.047214 2.815 0.005
L1.Burgenland -0.053306 0.032463 -1.642 0.101
L1.Kärnten -0.036225 0.017433 -2.078 0.038
L1.Niederösterreich 0.165914 0.068072 2.437 0.015
L1.Oberösterreich 0.130809 0.064362 2.032 0.042
L1.Salzburg 0.290397 0.034478 8.423 0.000
L1.Steiermark 0.034154 0.045251 0.755 0.450
L1.Tirol 0.159787 0.036793 4.343 0.000
L1.Vorarlberg 0.109575 0.031610 3.466 0.001
L1.Wien 0.067498 0.057385 1.176 0.240
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.065209 0.037506 1.739 0.082
L1.Burgenland 0.038491 0.025788 1.493 0.136
L1.Kärnten 0.050175 0.013849 3.623 0.000
L1.Niederösterreich 0.225698 0.054074 4.174 0.000
L1.Oberösterreich 0.266213 0.051127 5.207 0.000
L1.Salzburg 0.060573 0.027389 2.212 0.027
L1.Steiermark -0.006857 0.035946 -0.191 0.849
L1.Tirol 0.157331 0.029227 5.383 0.000
L1.Vorarlberg 0.068685 0.025110 2.735 0.006
L1.Wien 0.075248 0.045585 1.651 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188188 0.045065 4.176 0.000
L1.Burgenland 0.017596 0.030986 0.568 0.570
L1.Kärnten -0.058660 0.016640 -3.525 0.000
L1.Niederösterreich -0.095901 0.064974 -1.476 0.140
L1.Oberösterreich 0.177130 0.061432 2.883 0.004
L1.Salzburg 0.061441 0.032909 1.867 0.062
L1.Steiermark 0.226095 0.043191 5.235 0.000
L1.Tirol 0.483565 0.035118 13.770 0.000
L1.Vorarlberg 0.052127 0.030171 1.728 0.084
L1.Wien -0.049876 0.054773 -0.911 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153183 0.050968 3.005 0.003
L1.Burgenland -0.000932 0.035044 -0.027 0.979
L1.Kärnten 0.067154 0.018819 3.568 0.000
L1.Niederösterreich 0.201939 0.073484 2.748 0.006
L1.Oberösterreich -0.068871 0.069479 -0.991 0.322
L1.Salzburg 0.220786 0.037219 5.932 0.000
L1.Steiermark 0.108116 0.048848 2.213 0.027
L1.Tirol 0.083952 0.039718 2.114 0.035
L1.Vorarlberg 0.127603 0.034123 3.740 0.000
L1.Wien 0.108318 0.061947 1.749 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356889 0.030193 11.820 0.000
L1.Burgenland 0.008230 0.020760 0.396 0.692
L1.Kärnten -0.025371 0.011148 -2.276 0.023
L1.Niederösterreich 0.229447 0.043532 5.271 0.000
L1.Oberösterreich 0.150495 0.041159 3.656 0.000
L1.Salzburg 0.052816 0.022049 2.395 0.017
L1.Steiermark -0.016650 0.028937 -0.575 0.565
L1.Tirol 0.121645 0.023529 5.170 0.000
L1.Vorarlberg 0.073447 0.020214 3.633 0.000
L1.Wien 0.050470 0.036697 1.375 0.169
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039102 0.164408 0.183836 0.171268 0.147026 0.130733 0.068133 0.220832
Kärnten 0.039102 1.000000 0.002491 0.132460 0.027406 0.098995 0.430719 -0.048567 0.101647
Niederösterreich 0.164408 0.002491 1.000000 0.350355 0.174350 0.318412 0.134982 0.193698 0.342840
Oberösterreich 0.183836 0.132460 0.350355 1.000000 0.237438 0.345017 0.183846 0.180697 0.274429
Salzburg 0.171268 0.027406 0.174350 0.237438 1.000000 0.157501 0.141101 0.154193 0.142487
Steiermark 0.147026 0.098995 0.318412 0.345017 0.157501 1.000000 0.165862 0.149355 0.098459
Tirol 0.130733 0.430719 0.134982 0.183846 0.141101 0.165862 1.000000 0.125351 0.165279
Vorarlberg 0.068133 -0.048567 0.193698 0.180697 0.154193 0.149355 0.125351 1.000000 0.021410
Wien 0.220832 0.101647 0.342840 0.274429 0.142487 0.098459 0.165279 0.021410 1.000000